import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/dialog/filter_dialog/custom_filter_right_sheet.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/project_same_time_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/file_management/three_same_time/three_same_time_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 三同时列表页面
class ThreeSameTimePage extends StatelessWidget {
  ThreeSameTimePage({super.key});

  final controller = Get.put(ThreeSameTimeController());

  ///获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Row(
      children: [
        Expanded(
            child: CustomSearchEnter(
          height: 32.w,
          hintText: '请输入文件名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        )),
        AppGaps.hGap8,
        _screen(),
      ],
    );
  }

  ///筛选
  Widget _screen() {
    return Container(
      width: 36.w,
      height: 32.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 18.w,
        height: 16.w,
      ),
    ).clickOnce(controller.screen);
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value}) {
    return Row(
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        Expanded(
            child: Container(
          alignment: Alignment.centerRight,
          child: Text(
            value,
            style: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff495061),
            ),
          ),
        ))
      ],
    );
  }

  ///获取右侧筛选样式
  Widget _getFilterWidget() {
    return CustomFilterRightSheet(
      dataList: controller.filterList,
      onConfirm: controller.screenConfirm,
      isRadio: true,
      isShowTime: true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '三同时',
            ),
            key: controller.popRightScaffoldKey,
            endDrawer: Container(
              width: AppDimens.sw - 70.w,
              height: AppDimens.sh,
              color: Colors.white,
              child: _getFilterWidget(),
            ),
            body: Container(
              color: const Color(0xffF5F5F6),
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
              child: Column(
                children: [
                  _getSearchConditionWidget(),
                  AppGaps.vGap12,
                  Expanded(
                      child: CustomEasyRefreshList<ProjectSameTimeEntity>(
                    key: controller.globalKey,
                    dataLoad: (pageIndex, pageSize, {String? search}) async {
                      return controller.getListData(pageIndex, pageSize);
                    },
                    itemBuilder: (ProjectSameTimeEntity item, int index) {
                      return CustomCard(
                        onTap: () {
                          // 点击进入详情
                          Get.toNamed(AppRoutes.threeSameTimeDetails, arguments: item.id);
                        },
                        padding: EdgeInsets.zero,
                        titleWidget: Padding(
                          padding: EdgeInsets.all(14.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              SvgPicture.asset(AppImages.icon_title),
                              AppGaps.hGap10,
                              Expanded(
                                child: Text(
                                  item.projectName!,
                                  style: TextStyle(
                                    fontSize: 15.sp,
                                    fontWeight: FontWeight.w500,
                                    color: const Color(0xff333333),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                        divider: CustomCard.builtinDivider,
                        content: Padding(
                          padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 16.w),
                          child: Column(
                            children: [
                              _getTextView(title: '状态：', value: item.projectNowStatusName!),
                              AppGaps.vGap12,
                              _getTextView(title: '项目类型：', value: item.projectTypeName!),
                              AppGaps.vGap12,
                              _getTextView(title: '总体项目开始时间：', value: item.projectBeginDate!),
                              AppGaps.vGap12,
                              _getTextView(title: '总体项目结束时间：', value: item.projectEndDate!),
                            ],
                          ),
                        ),
                      );
                    },
                  ))
                ],
              ),
            ),
          );
        });
  }
}
